<?php
require_once ROOT_ADMIN_MODELS.DS.'Models_Base.php';
class Models_Forum extends Models_Base{
	public function __construct(){
		parent::__construct();
		$this->_key="id";
		$this->_table="forum";
	}
	
	public function listforum($status)
	{
		$sql="	SELECT *
				FROM forum 
				WHERE status != -1";
		if($status != "")
			$sql.=" AND status != 0 ";
		$sql.="		ORDER BY number";
		$data=$this->_db->fetchAll($sql,null,Zend_Db::FETCH_OBJ);
		return $data;
	}
	
	public function setstatus($id,$status)
	{
		$sql = "UPDATE forum SET status = $status WHERE id = $id";
		$this->_db->query($sql);
	}
	
	public function delforum($id){
		$sql = "DELETE FROM forum WHERE id = $id";
		$this->_db->query($sql);
	}
	
	public function counttypenew($id){
		$sql = "SELECT COUNT(id) FROM typenews WHERE forum_id = $id";
		$count = $this->_db->fetchOne($sql);
		return $count;
	}
	
	public function getforumbyid($id){
		$sql = "SELECT * FROM forum 
				WHERE id = $id 
				AND status != -1";
		$return = $this->_db->fetchRow($sql);
		return $return;
	}
	
	public function updatenumber($id,$number)
	{
		$sql = "UPDATE forum SET number = $number WHERE id = $id";
		$this->_db->query($sql);
	}
}
